package cn.bocweb.spinning.view.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.GetIhomeBean;
import cn.bocweb.spinning.util.DeviceUtil;
import cn.bocweb.spinning.view.common.MyAdapter;

/**
 * Created by chenchangxing on 16/7/4.
 */
public class MainInfoAdapter extends MyAdapter<GetIhomeBean.DataEntity> {

    public MainInfoAdapter(Context context, List<GetIhomeBean.DataEntity> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_main_info1, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (!TextUtils.isEmpty(list.get(position).getImg().get(0))) {
            Glide
                    .with(context)
                    .load(list.get(position).getImg().get(0))
                    .into(holder.mImgIcon);
        }
        holder.mTvTitle.setText(list.get(position).getTitle());
        holder.mTvContent.setText(list.get(position).getContent());
        holder.mTvTime.setText(
                DeviceUtil.getTimeByTwoTimeStampForPhp(
                        Long.parseLong(list.get(position).getTimeline()) * 1000,
                        System.currentTimeMillis()));

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.img_icon)
        ImageView mImgIcon;
        @Bind(R.id.tv_title)
        TextView mTvTitle;
        @Bind(R.id.tv_content)
        TextView mTvContent;
        @Bind(R.id.tv_time)
        TextView mTvTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
